package com.galeno.redis;

import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * @author galeno
 * @Title:
 * @Description: \
 * @date 2021/9/1421:47
 */
public class RedisSetAPI {
    public static void main(String[] args) {
        Jedis galeno01 = new Jedis("galeno01", 6379);
        //集合中插入数据
        galeno01.sadd("f:zs","a","b","c");
        galeno01.sadd("f:ls","b","c","d");
        //获取一个set中的数据
        Set<String> smembers = galeno01.smembers("f:zs");
        System.out.println(smembers);

        //判断一个元素是否存在于指定的set中

        Boolean sismember = galeno01.sismember("f:zs", "呵呵");
        System.out.println(sismember);
        //求交集
        Set<String> sdiff = galeno01.sdiff("f:zs", "f:ls");
        System.out.println(sdiff);

        //求并集
        Set<String> sunion = galeno01.sunion("f:zs", "f:ls");
        System.out.println(sunion);

        /**
         * 求交集并集并把结果保存到另一set中
         */
        Long sdiffstore = galeno01.sdiffstore("f:ww", "f:zs", "f:ls");
        System.out.println(galeno01.smembers("f:ww"));


    }
}
